<?php

  class ProductAction extends CommonAction{
    
	public function index(){
	
	
	  $where['status']=array('eq','1');
	
	  $re=$this->page('buyer','10','id desc',$where);
	  
	  $i=-1;
	  
	  foreach($re as $v){
	   
	    $i++;
		
		$pianku=M('pianku')->where('id="%s"',$v['vid'])->find();
		
		$re[$i]['title']=$pianku['title'];
	  
	  
	  }
	  
	  
	  
	  
	  $this->re=$re;
	  
	  //今日收益 今日打赏
	  $today=strtotime(date('Y-m-d'));
	  $where['time']=array('gt',$today);
	  
	  $todaymoneys=M('buyer')->where($where)->select();
	  $jinrishouyi=0;
	  $jinridashang=0;
	  foreach($todaymoneys as $v){
	    $jinridashang+=$v['money'];
		$jinrishouyi+=$v['shouyimoney'];
	  }
	  
	  $sys=M('system')->where('id=1')->find();
	  $this->jinrishouyi=round($jinridashang*($sys['yongjin']/100),2);
	  $this->jinridashang=round($jinridashang,2);
	  //今日计算结束
	  
	  
	  
	  //计算今日返现
	  
	  
	  $f['time']=array('gt',$today);
	  $fanli=M('fanli')->where($f)->field('money')->select();
	  
	  //dump($fanli);
	  
	  $fm=0;
	  foreach($fanli as $v){
	  
	  $fm+=$v['money'];
	  }
	  
	  $this->fm=$fm;
	  
	 // dump($fm);
	  
	  
	  $this->display();
	
	}
	
	
	public function datu(){
	
	  $this->re=M('pianku')->where('id="%s"',$_GET['id'])->find();
	  
	  $this->sys=M('system')->where('id=1')->find();
	  
	 // dump($this->sys);
	
	  layout(false);
	
	  $this->display();
	
	}
	
	
	
	public function search(){
	
	  $start=strtotime($_GET['day']);
	  $this->day=$_GET['day'];
	  $end=$start+86400;
	  $where['time']=array(array('gt',$start),array('lt',$end),'and');
	  $where['status']=array('eq','1');
	  
	  
	 
	  
	
	  $re=$this->page('buyer','10','id desc',$where);
	  
	    $i=-1;
	  
	  foreach($re as $v){
	   
	    $i++;
		
		$pianku=M('pianku')->where('id="%s"',$v['vid'])->find();
		
		$re[$i]['title']=$pianku['title'];
	  
	  
	  }
	  
	  $this->re=$re;
	  
	   //今日收益 今日打赏
	  $today=strtotime(date('Y-m-d'));
	  $where['time']=array('gt',$today);
	   $end=$start+86400;
	  $where['time']=array(array('gt',$start),array('lt',$end),'and');
	  $todaymoneys=M('buyer')->where($where)->select();
	  
	 // dump(M('buyer')->getlastsql());
	  
	  $jinrishouyi=0;
	  $jinridashang=0;
	  foreach($todaymoneys as $v){
	    $jinridashang+=$v['money'];
		$jinrishouyi+=$v['shouyimoney'];
	  }
	  
	  $sys=M('system')->where('id=1')->find();
	  $this->jinrishouyi=round($jinridashang*($sys['yongjin']/100),2);
	  $this->jinridashang=round($jinridashang,2);
	  //今日计算结束
	  
	  
	  
	  $f['time']=array(array('gt',$start),array('lt',$end),'and');
	  $fanli=M('fanli')->where($f)->field('money')->select();
	  
	  //dump($fanli);
	  
	  $fm=0;
	  foreach($fanli as $v){
	  
	  $fm+=$v['money'];
	  }
	  
	  $this->fm=$fm;
	  
	  
	
	  $this->display();
	
	}
	
	
	public function se(){
	
	  $start=strtotime($_GET['start']);
	 // $this->day=$_GET['day'];
	  $end=strtotime($_GET['end'])+86400;
	  $where['time']=array(array('gt',$start),array('lt',$end),'and');
	  $where['status']=array('eq','1');
	
	  $re=$this->page('buyer','10','id desc',$where);
	  
	     $i=-1;
	  
	  foreach($re as $v){
	   
	    $i++;
		
		$pianku=M('pianku')->where('id="%s"',$v['vid'])->find();
		
		$re[$i]['title']=$pianku['title'];
	  
	  
	  }
	  
	  
	  $this->re=$re;
	  
	   //今日收益 今日打赏
	  $today=strtotime(date('Y-m-d'));
	 
	  $todaymoneys=M('buyer')->where($where)->select();
	  
	 // dump(M('buyer')->getlastsql());
	  
	 
	  $sousuori=0;
	  foreach($todaymoneys as $v){
	    $sousuori+=$v['money'];
		
	  }
	  
	  $sys=M('system')->where('id=1')->find();
	  $this->sousuori=$sousuori;
	  
	  $this->shouyi=round($sousuori*($sys['yongjin']/100),2);
	  
	  
	  
	  
	  $f['time']=array(array('gt',$start),array('lt',$end),'and');
	  $fanli=M('fanli')->where($f)->field('money')->select();
	  
	  //dump($fanli);
	  
	  $fm=0;
	  foreach($fanli as $v){
	  
	  $fm+=$v['money'];
	  }
	  
	  $this->fm=round($fm,2);
	  
	  
	  
	  
	  
	  
	
	  //今日计算结束
	  
	  $this->start=$_GET['start'];
	  $this->end=$_GET['end'];
	  
	
	  $this->display();
	
	
	
	}
	
  
  
  
  }